package pers.youqu.search.controller;

import com.leyou.starter.elastic.entity.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import pers.youqu.common.dto.PageDTO;
import pers.youqu.search.dto.SearchParamDTO;
import pers.youqu.search.entity.Goods;
import pers.youqu.search.service.SearchService;
import reactor.core.publisher.Mono;

import java.security.Key;
import java.util.List;
import java.util.Map;

/**
 * @author Jason
 * @version 1.0.0
 * @date 2020/12/12 19:08
 * @Description TODO
 */
@RestController
public class SearchController {

    @Autowired
    private SearchService searchService;

    /**
     * 搜索框关键字补全
     * @param key 搜索框输入值
     * @return 可以补全的文本内容
     */
    @GetMapping("/goods/suggestion")
    public Mono<List<String>> suggestionKey(@RequestParam("key") String key) {
        return searchService.suggestionKey(key);
    }

    /**
     * SPU商品
     * @param searchParamDTO
     * @return
     */
    @PostMapping("/goods/list")
    public Mono<PageInfo<Goods>> pageList(@RequestBody SearchParamDTO searchParamDTO) {
        return searchService.pageList(searchParamDTO);
    }

    @PostMapping("/goods/filter")
    public Mono<Map<String,List<?>>> findFilters(@RequestBody SearchParamDTO searchParamDTO) {
        return searchService.findFilters(searchParamDTO);
    }



}
